#include "EquationSolver.h"
using namespace std;

class Function1 : public Function
{
public:
    double operator()(double _x)
    {
        double f;
        f = sin(_x / 2) - 1;
        return f;
    }
};

class Function2 : public Function
{
public:
    double operator()(double _x)
    {
        double f;
        f = exp(_x) - tan(_x);
        return f;
    }
};

class Function3 : public Function
{
public:
    double operator()(double _x)
    {
        double f;
        f = pow(_x, 3) - 12 * pow(_x, 2) + 3 * _x + 1;
        return f;
    }
};

int main(int argc,char *argv [ ]){
    cout << "D:" << endl;
    Function1 func1;
    Function2 func2;
    Function3 func3;
    Secant sec1(0, M_PI / 2, eps, 50, func1);
    Secant sec1_1(M_PI / 3, 2 * M_PI / 3, eps, 50, func1);
    Secant sec2(1, 1.4, eps, 50, func2);
    Secant sec2_1(1.8, 2, eps, 50, func2);
    Secant sec3(0, -0.5, eps, 50, func3);
    Secant sec3_1(-0.3, 0.5, eps, 50, func3);
    double root1 = sec1.solve(), root1_1 = sec1_1.solve(), root2 = sec2.solve(), root2_1 = sec2_1.solve(), root3 = sec3.solve(), root3_1 = sec3_1.solve();
    cout << "The results generated by the first function with different initial values are: " << root1 << ' ' << root1_1 << " f(root) are: " << func1(root1) << ',' << func1(root1_1) << endl;
    cout << "The results generated by the second function with different initial values are: " << root2 << ' ' << root2_1 << " f(root) are: " << func2(root2) << ',' << func2(root2_1) << endl;
    cout << "The results generated by the third function with different initial values are: " << root3 << ' ' << root3_1 << " f(root) are: " << func3(root3) << ',' << func3(root3_1) << endl;
    return 0;
}
